//
// File:	SDK.cpp
// Author:	Thomas TISSOT-DUPONT
// E-mail:	<thomas.tissotdupont@free.fr>
// Create:	27/04/2010 22:47:27
// Purpose:	
//
#include "SDK.hpp"
#include "Trace.hpp"

//------------------------------------------------------------------
// Constructor / Destructor
//------------------------------------------------------------------
SDK::SDK()
	:	m_module()
{
}

SDK::~SDK()
{
}

//------------------------------------------------------------------
// Load
//------------------------------------------------------------------
bool SDK::Load(const std::string &sModulePath, const std::string &sSDKMainFunctionName)
{
	if (!m_module.Load(sModulePath))
	{
		Trace::error << "SDK::Load: Cannot load module: " << sModulePath << std::endl;
		return false;
	}

	tPfnSDKMain fnSDKMain = reinterpret_cast<tPfnSDKMain>(m_module.FindSymbol(sSDKMainFunctionName));
	if (fnSDKMain == NULL)
	{
		Trace::error << "SDK::Load: Cannot load function: " << sSDKMainFunctionName << std::endl;
		return false;
	}

	//Make the global pointers structure
	GlobalVariables::Pointers pointers;
	pointers.engine = &GlobalVariables::Engine::Get();
	pointers.factoryManager = &GlobalVariables::FactoryManager::Get();
	pointers.config = &GlobalVariables::Config::Get();
	pointers.global = &GlobalVariables::Global::Get();
	pointers.displayManager = &GlobalVariables::DisplayManager::Get();
	pointers.inputManager = &GlobalVariables::InputManager::Get();
	pointers.guiManager = &GlobalVariables::GuiManager::Get();
	pointers.entityManager = &GlobalVariables::EntityManager::Get();
	pointers.gameruleManager = &GlobalVariables::GameRuleManager::Get();
	pointers.soundManager = &GlobalVariables::SoundManager::Get();
	pointers.eventManager = &GlobalVariables::EventManager::Get();

	//Call the SDK main function
	return (*fnSDKMain)(pointers);
}
